package com.hkg.springcloud.controller;

import com.hkg.springcloud.ResultUtil.CommonResult;
import com.hkg.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @ClassName : OrderController
 * @Author : 坏老爷
 * @Date: 2020-03-21 21:18
 */
@RestController
@Slf4j
public class OrderController {
//    private static final String PATHPARAM = "http://localhost:8001";

    private static final String PATHPARAM = "http://CLOUD-PAYMENT-SERVICE";
    @Autowired
    private RestTemplate restTemplate;

    /**
     * 添加
     *
     * @return
     */
    @PostMapping("consumer/payment/create")
    public CommonResult<Payment> create(Payment payment) {
        return restTemplate.postForObject(PATHPARAM + "/payment/create", payment, CommonResult.class);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @PostMapping("consumer/payment/query/{id}")
    public CommonResult<Payment> queryById(@PathVariable("id") Long id) {
        return restTemplate.postForObject(PATHPARAM + "/payment/query/" + id, id, CommonResult.class);
    }

    /**
     * 取消
     *
     * @param id
     * @return
     */
    @PostMapping("consumer/payment/delete/{id}")
    public CommonResult<Payment> delete(@PathVariable("id") Long id) {
        return restTemplate.postForObject(PATHPARAM + "/payment/delete/" + id, id, CommonResult.class);
    }

    /**
     * 查询所有支付订单
     *
     * @return
     */
    @PostMapping("consumer/payment/queryAll")
    public CommonResult<List<Payment>> queryAll() {
        return restTemplate.postForObject(PATHPARAM + "/payment/queryAll", null, CommonResult.class);
    }

    /**
     * 删除所有支付订单
     *
     * @return
     */
    @PostMapping("consumer/payment/deleteAll")
    public CommonResult<List<Payment>> deleteAll() {
        return restTemplate.postForObject(PATHPARAM + "/payment/deleteAll", null, CommonResult.class);
    }
}
